<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Modal\memberModal;
use App\Admin\Repositories\BranchCourt;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BranchCourtController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BranchCourt(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('hospital_nick','分院名称');
            $grid->column('hospital_address','分院地址');
            $grid->column('business_hours','工作时间');
            $grid->column('hospital_img','分院图片')->image();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->tools(function  (Grid\Tools  $tools)  {
                //Excel导入
                $tools->append(new  memberModal());
            });
            $grid->filter(function (Grid\Filter $filter) {
                // 更改为 panel 布局
                $filter->panel();
                $filter->equal('id');
                $filter->like('hospital_nick');
            });
            $grid->export();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new BranchCourt(), function (Show $show) {
            $show->field('hospital_nick');
            $show->field('hospital_address');
            $show->field('business_hours');
            $show->field('hospital_img')->image();
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BranchCourt(), function (Form $form) {
            $form->text('hospital_nick','分院名称');
            $form->text('hospital_address','分院地址');
            $form->text('business_hours','工作时间');
            $form->image('hospital_img','分院图片')->disk('qiniu')->saveFullUrl()->uniqueName()->required();
        });
    }
}
